package com.denlaku.longan.core;

import com.google.common.util.concurrent.RateLimiter;

import java.time.Duration;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @author tianx
 */
public class RateLimiterManager {
    private static final ConcurrentMap<String, RateLimiter> MAP = new ConcurrentHashMap<>();

    public static RateLimiter getRateLimiter(String cacheKey, double permitsPerSecond, Duration warmupPeriod) {
        return MAP.computeIfAbsent(cacheKey, key -> RateLimiter.create(permitsPerSecond, warmupPeriod));
    }

}
